//
//  TJBuySellNeedAuthController.m
//  Teleport
//
//  Created by hc-101 on 2020/6/16.
//  Copyright © 2020 xtjun. All rights reserved.
//

#import "TJBuySellNeedAuthController.h"


@interface TJBuySellNeedAuthController ()<UIGestureRecognizerDelegate>

//@property (strong, nonatomic) NSMutableArray *datas;
@property (weak, nonatomic) UIView *maskView;
@property (weak, nonatomic) UIView *contentView;

@end


@implementation TJBuySellNeedAuthController



- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        self.modalPresentationStyle = UIModalPresentationCustom;
    }
    return self;
}
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    [UIView animateWithDuration:0.25 animations:^{
        self.maskView.backgroundColor = UIColor.tj_alertMaskColor;
        self.contentView.center = self.view.center;
    } completion:^(BOOL finished) {
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
//    _datas = @[].mutableCopy;
    
    
    self.view.backgroundColor = UIColor.clearColor;
    
    UIView *maskView = [UIView tj_addToView:self.view];
    maskView.backgroundColor = [UIColor.tj_alertMaskColor colorWithAlphaComponent:0];
    maskView.frame = self.view.bounds;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didClickDismissButton)];
    [maskView addGestureRecognizer:tap];
    tap.delegate = self;
    
    UIImageView *contentView = [UIImageView tj_addToView:maskView];
    contentView.userInteractionEnabled = YES;
    contentView.image = [UIImage imageNamed:@"alertAuthBg_icon"];
    UIView *headerView = [UIView tj_addToView:contentView];
    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.height.offset(80);
        make.top.offset(0);
    }];
    
    
    UILabel *nameLabel = [UILabel lableWithSuperView:headerView font:MediumFont(18) color:UIColor.whiteColor title:self.title textAlignment:NSTextAlignmentLeft];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.left.offset(16);
        make.right.offset(-16);
    }];
    
    
    UIButton *phoneAuthButton = [UIButton buttonWithSuperView:contentView font:UIFont_Px(15) color:UIColor_Hex(0x272727) title:@"绑定手机".localizedString];
    [phoneAuthButton setImage:[UIImage imageNamed:@"alert_phone_icon"] forState:UIControlStateNormal];
    [phoneAuthButton setImage:[UIImage imageNamed:@"alert_phone_icon"] forState:UIControlStateHighlighted];
    [phoneAuthButton addTarget:self action:@selector(didClickPhoneAuthButton) forControlEvents:UIControlEventTouchUpInside];
    [phoneAuthButton setImagePosition:LXMImagePositionLeft spacing:26];
    [phoneAuthButton setContentHorizontalAlignment:(UIControlContentHorizontalAlignmentLeft)];
    [phoneAuthButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-120);
        make.top.equalTo(headerView.mas_bottom).offset(30);
        make.left.offset(20);
        make.height.offset(30);
    }];
    
    UILabel *phoneAuthResultLabel = [UILabel lableWithSuperView:contentView font:UIFont_Px(15) color:UIColor_Hex(0x272727) title:@"已绑定".localizedString textAlignment:NSTextAlignmentLeft];
    [phoneAuthResultLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(phoneAuthButton);
        make.right.offset(-20);
    }];
    
    UIButton *bankAuthButton = [UIButton buttonWithSuperView:contentView font:UIFont_Px(15) color:UIColor_Hex(0x272727) title:@"绑定本人实名银行卡".localizedString];
    [bankAuthButton setImage:[UIImage imageNamed:@"alert_bank_icon"] forState:UIControlStateNormal];
    [bankAuthButton setImage:[UIImage imageNamed:@"alert_bank_icon"] forState:UIControlStateHighlighted];
    [bankAuthButton addTarget:self action:@selector(didClickBankAuthButton) forControlEvents:UIControlEventTouchUpInside];
    [bankAuthButton setImagePosition:LXMImagePositionLeft spacing:16];
    [bankAuthButton setContentHorizontalAlignment:(UIControlContentHorizontalAlignmentLeft)];
    [bankAuthButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-120);
        make.top.equalTo(phoneAuthButton.mas_bottom).offset(10);
        make.left.offset(20);
        make.height.equalTo(phoneAuthButton);
    }];
    
    UILabel *bankAuthResultLabel = [UILabel lableWithSuperView:contentView font:UIFont_Px(15) color:UIColor_Hex(0x272727) title:@"已绑定".localizedString textAlignment:NSTextAlignmentLeft];
    [bankAuthResultLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(bankAuthButton);
        make.right.offset(-20);
    }];
    
    UIButton *IdCardButton = [UIButton buttonWithSuperView:contentView font:UIFont_Px(15) color:UIColor_Hex(0x272727) title:@"身份认证".localizedString];
    [IdCardButton setImage:[UIImage imageNamed:@"alert_auth_icon"] forState:UIControlStateNormal];
    [IdCardButton setImage:[UIImage imageNamed:@"alert_auth_icon"] forState:UIControlStateHighlighted];
    [IdCardButton addTarget:self action:@selector(didClickIdCardAuthButton) forControlEvents:UIControlEventTouchUpInside];
    [IdCardButton setImagePosition:LXMImagePositionLeft spacing:16];
    [IdCardButton setContentHorizontalAlignment:(UIControlContentHorizontalAlignmentLeft)];
    [IdCardButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-120);
        make.top.equalTo(bankAuthButton.mas_bottom).offset(10);
        make.left.offset(20);
        make.height.equalTo(phoneAuthButton);
    }];
    
    UILabel *IdCardAuthResultLabel = [UILabel lableWithSuperView:contentView font:UIFont_Px(15) color:UIColor_Hex(0x272727) title:@"已绑定".localizedString textAlignment:NSTextAlignmentLeft];
    [IdCardAuthResultLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(IdCardButton);
        make.right.offset(-20);
    }];
    
    contentView.frame = CGRectMake(16, -300, KScreenWidth - 32, ZOOM(250));
    
    _maskView = maskView;
    _contentView = contentView;
    
    TJUserInfo *userInfo = TJUserInfo.readInfo;
    BOOL bandingPhone = YES;
    BOOL bandingBank = userInfo.bankCard.replacingEmptyString.length;
    BOOL bandingIdCard = userInfo.cardNo.replacingEmptyString.length;
    
    if (!bandingPhone) {
        phoneAuthResultLabel.textColor = UIColor_Hex(0x666666);
        phoneAuthResultLabel.text = @"未绑定".localizedString;
        [phoneAuthResultLabel addTapGesturesWithTarget:self action:@selector(tapPhoneAuthResultLabel)];
    } else {
        phoneAuthResultLabel.text = @"已绑定".localizedString;
        phoneAuthResultLabel.textColor = UIColor_Hex(0x3882E8);
    }
    
    if (!bandingBank) {
        bankAuthResultLabel.text = @"未绑定".localizedString;
        bankAuthResultLabel.textColor = UIColor_Hex(0x666666);
        [bankAuthResultLabel addTapGesturesWithTarget:self action:@selector(tapBankAuthResultLabel)];
    } else {
        bankAuthResultLabel.text = @"已绑定".localizedString;
        bankAuthResultLabel.textColor = UIColor_Hex(0x3882E8);
    }
    
    if (!bandingIdCard) {
        IdCardAuthResultLabel.text = @"未绑定".localizedString;
        IdCardAuthResultLabel.textColor = UIColor_Hex(0x666666);
        [IdCardAuthResultLabel addTapGesturesWithTarget:self action:@selector(tapIdCardAuthResultLabel)];
    } else {
        IdCardAuthResultLabel.text = @"已绑定".localizedString;
        IdCardAuthResultLabel.textColor = UIColor_Hex(0x3882E8);
    }
    
    
}
/**身份证 未绑定点击**/
- (void)tapIdCardAuthResultLabel {
    TJLog(@"身份证 未绑定点击");
    
}
/**手机 未绑定点击**/
- (void)tapPhoneAuthResultLabel {
    TJLog(@"手机 未绑定点击");
}
/**银行卡 未绑定点击**/
- (void)tapBankAuthResultLabel {
    TJLog(@"银行卡 未绑定点击");
}

/**手机图标点击**/
- (void)didClickPhoneAuthButton {
    TJLog(@"手机图标点击");
}
/**银行卡图标点击**/
- (void)didClickBankAuthButton {
    TJLog(@"银行卡图标点击");
}
/**身份证图标点击**/
- (void)didClickIdCardAuthButton {
    TJLog(@"身份证图标点击");
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if (touch.view != self.maskView) {
        return NO;
    }else {
        return YES;
    }
}


- (void)didClickDismissButton {
    [self dismissComplete:nil];
}



- (void)dismissComplete:(void (^)(void))complete {
    
    [UIView animateWithDuration:0.25 animations:^{
        self.maskView.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0];
        self.contentView.tj_centerY = -300;
    } completion:^(BOOL finished) {
        [self dismissViewControllerAnimated:NO completion:^{
            if (complete) complete();
        }];
    }];
}



//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//
//    [self dismissComplete:^{
//        //        if (self.selectComplete) {
//        //            self.selectComplete(self.datas[indexPath.row]);
//        //        }
//    }];
//}




@end
